package com.htgd.gardenexpo.controller;

import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.dto.GeConTheaterPlanDTO;
import com.htgd.gardenexpo.dto.MovieBlessDTO;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConTheaterMovie;
import com.htgd.gardenexpo.entity.GeConTheaterMovieBless;
import com.htgd.gardenexpo.page.MovieBlessQuery;
import com.htgd.gardenexpo.service.GeConTheaterMovieBlessService;
import com.htgd.gardenexpo.utils.DateUtils;
import com.htgd.gardenexpo.vo.GeConTheaterMovieBlessVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * @author: 王秀田
 * @date: 2024/11/12 18:08
 * @description: 观影祝福管理
 */
@RestController
@RequestMapping("/api/movieBless")
@Api(tags = "观影祝福")
public class GeConTheaterMovieBlessController {

    @Autowired
    private GeConTheaterMovieBlessService geConTheaterMovieBlessService;

    @GetMapping(value = "/list")
    @ApiOperation("查询列表")
    public CommonResult<List<GeConTheaterMovieBlessVO>> list(MovieBlessQuery movieBlessQuery) {
        PageInfo<GeConTheaterMovieBlessVO> list = geConTheaterMovieBlessService.pageList(movieBlessQuery);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

    @GetMapping(value = "/blessList")
    @ApiOperation("查询小程序祝福列表")
    public CommonResult<List<GeConTheaterMovieBlessVO>> blessList(MovieBlessQuery movieBlessQuery, HttpServletRequest request) {
        PageInfo<GeConTheaterMovieBlessVO> list = geConTheaterMovieBlessService.blessList(movieBlessQuery,request);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

    @PostMapping(value = "/add")
    @ApiOperation("添加祝福语")
    public CommonResult add(@RequestBody MovieBlessDTO movieBless, HttpServletRequest request) {
        try {
            geConTheaterMovieBlessService.add(movieBless,request);
            return CommonResult.success("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.success("添加失败");
        }
    }

    @PostMapping(value = "/review")
    @ApiOperation("审核")
    public CommonResult review(@RequestBody GeConTheaterMovieBless geConTheaterMovieBless) {
        try {
            GeConTheaterMovieBlessVO movieBless = geConTheaterMovieBlessService.getGeConTheaterMovieBlessVOById(geConTheaterMovieBless.getId());
            String showTime = movieBless.getShowTime();
            String movieName = movieBless.getMovieName();
            if(Objects.equals(geConTheaterMovieBless.getStatus(),"1")){//审核通过
                geConTheaterMovieBless.setAuditContent("您的祝福已完成审核，将会在"+ DateUtils.stringToString(showTime.substring(0,10)) +"元宇宙红色经典剧场《"+movieName+"》剧目中同步播放，雨花数据线公园祝您观影愉快！");
            }else{
                geConTheaterMovieBless.setAuditContent("您的祝福审核不通过，违规相关规定！");
            }
            geConTheaterMovieBless.setAuditTime(LocalDateTime.now());
            geConTheaterMovieBlessService.updateById(geConTheaterMovieBless);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.error("操作失败");
        }
        return CommonResult.success("操作成功");
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation("删除")
    public CommonResult delete(String id) {
        GeConTheaterMovie geConTheaterMovie = new GeConTheaterMovie();
        geConTheaterMovie.setId(id);
        geConTheaterMovie.setIsDelete("2");
        geConTheaterMovieBlessService.removeById(id);
        return CommonResult.success("删除成功");
    }

}
